<?php
require_once('include/GeneralTop.php');
require('include/class/db.php');
$db = new db;

$token = mysql_escape_string($_GET['token']);
//$server = mysql_escape_string($_GET['symbol']);
//switch($server)
$sql = "select member_id from member_info where unsubscribe_token='".$token."'";
$query = $db->query($sql);
if(1 > $db->num($query)) {
	$sql_sub = "select ECId from emailcollection where unsubscribe_token='".$token."'";
	$query_sub = $db->query($sql_sub);
	if(1 > $db->num($query_sub)) {
		//other tables
		die("<div align='center'>error occured</div>");
	}
	else {
		$row_sub = $db->fetch($query_sub);
		$update_sub = "update emailcollection set status='2' where ECId='".$row_sub['ECId']."'";
		$db->query($update_sub);
		echo "<div align='center'>Unsubscribe successfully</div>";
	}
}
else {
	$row = $db->fetch($query);
	$update = "update member_info set if_send_newsletter='2' where member_id='".$row['member_id']."'";
	$db->query($update);
	echo "<div align='center'>Unsubscribe successfully</div>";
}

?>